home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’90 / Validate Text Entry / setdrug.f < prev    next >
Encoding:
Text File  |  1989-09-19  |  6.1 KB  |  200 lines  |  [TEXT/MPS ]

  1. !!M Inlines.f
  2. !!S USER
  3.     subroutine setdrug
  4.  
  5.       implicit none
  6.       
  7. !!SETC USINGINCLUDES = .FALSE.
  8.     Include    'TYPES.F'
  9.     Include    'DIALOGS.F'
  10.     include 'OSUTILS.F'
  11.     include 'SANE.F'
  12.  
  13.     Include    'Constants.inc'
  14.     Include    'common.inc'
  15.       Include 'Drug.inc'
  16.       Include 'format.inc'
  17.       Include 'savestuff.inc'
  18.  
  19.     Extended    msgtime 
  20.  
  21.     pointer /ParamBlockRec/ MyCntrlParam
  22.  
  23.     record /decform/ f
  24.     integer*1 r
  25.     extended x
  26.     string*255 s , ResourceNameString
  27.     string*8 bagnumString
  28.  
  29.       integer*4 itemHandle , prevPort
  30.     pointer /DialogRecord/ ptr
  31.     RECORD    /DRUGHandleType/ DRUGHandle
  32.  
  33.     pointer /resourcePtrType/ formatHandle
  34.       integer*2 ItemType , ItemHit , theID
  35.     record /Rect/ box 
  36.  
  37.     external itemGlue , NumValFilter , itemGlue2
  38.  
  39.     integer*4    dose_handle  , volume_handle , conc_handle
  40.     integer*4    dleft_handle , vleft_handle
  41.     integer*2    bagnum , osErr
  42.  
  43.       integer*2 new_drug_bag , Cancel
  44.     integer*2 Drug_amount_num , Diluent_vol_num , Concentration_num
  45.     integer*2 Drug_remaining_num , Diluent_remaining_num
  46.     integer*2 default_num
  47.     INTEGER*2 validateItem
  48.       parameter ( new_drug_bag             =    1)
  49.       parameter ( Cancel                    =    2)
  50.       parameter ( Drug_amount_num         =    3)
  51.       parameter ( Diluent_vol_num            =    4)
  52.       parameter ( Concentration_num        =    5)
  53.       parameter ( Drug_remaining_num        =    6)
  54.       parameter ( Diluent_remaining_num     =    7)
  55.     parameter ( default_num                =     9)
  56.     PARAMETER ( validateItem             =    10)
  57.     
  58.       logical DONE
  59.     
  60.     extended temp_dose , temp_conc
  61.     integer*4 temp_volume
  62.  
  63.     DATA bagnum        / 0 /
  64.     save bagnum
  65.  
  66. C  Set the SANE environment to round to the nearest value, and use fixed
  67. C  notation with one significant figure for numeric to string conversion
  68.  
  69.     r = TONEAREST
  70.     call SETROUND(r)
  71.     f.style = FIXEDDECIMAL
  72.     f.digits = 1
  73.     
  74.     ptr = GetNewDialog ( %val(int2(setdrug_DgId)) , %val(0) , %val(-1) )
  75.     call GetPort ( prevPort )
  76.     call SetPort ( %val(ptr) )
  77.  
  78.     formatHandle = GetResource ( %val ('Frm#') , %val(int2(setdrug_DgId)) )
  79.     ptr^.window.refCon = formatHandle
  80.     origField = .true.
  81.     good = .true.
  82.  
  83. C  Set the proc for userItem enclosing all the validated editText fields
  84.  
  85.     call GetDItem ( %val(ptr) , %val(int2(validateItem))    , ItemType , itemHandle , box )
  86.     ItemType = userItem+itemDisable
  87.     call SetDItem ( %val(ptr) , %val(int2(validateItem)) , %val(ItemType) , 
  88.     1                itemGlue , box )
  89.  
  90. C  Set the proc for the userItem enclosing the default button. This proc handles
  91. C  dimming the button when there are invalid entries in the editText fields, and
  92. C  draws the roundRect around the button
  93.  
  94.     call GetDItem ( %val(ptr) , %val(formatHandle^.Ptr^.okItem) , ItemType , 
  95.     1                itemHandle , box )
  96.     ItemType = userItem+itemDisable
  97.     Call InsetRect ( box , %val(int2(-4)) , %val(int2(-4)) )
  98.     call SetDItem ( %val(ptr) , %val(formatHandle^.Ptr^.defaultItem) , %val(ItemType) , 
  99.     1                itemGlue2 , box )
  100.  
  101.     ptr^.aDefItem = formatHandle^.Ptr^.okItem
  102.  
  103. c  Get handles to dialog items
  104.  
  105.     call GetDItem ( %val(ptr) , %val( Drug_amount_num) , ItemType , dose_handle  , box )
  106.     call GetDItem ( %val(ptr) , %val( Diluent_vol_num)        , ItemType , volume_handle, box )
  107.     call GetDItem ( %val(ptr) , %val( Concentration_num)    , ItemType , conc_handle  , box )
  108.     call GetDItem ( %val(ptr) , %val( Drug_remaining_num)    , ItemType , dleft_handle , box )
  109.     call GetDItem ( %val(ptr) , %val( Diluent_remaining_num), ItemType , vleft_handle , box )
  110.  
  111. c  Set initial item values (Mike, I would take it as a personal favor if dose_hung could be
  112. c  in units of mg instead of µg)
  113.  
  114.     temp_dose = dose_hung / 1000.
  115.     call NUM2STR( f , temp_dose , %ref(s) )
  116.     call SetIText ( %val(dose_handle) , %ref(s) )
  117.  
  118.     temp_volume = volume_hung
  119.     call NumToString ( %val(temp_volume) , %ref(s) )
  120.     call SetIText ( %val(volume_handle) , %ref(s) )
  121.  
  122.     temp_conc = drug_conc
  123.     call NUM2STR( f , temp_conc , %ref(s) )
  124.     call SetIText ( %val(conc_handle) , %ref(s) )
  125.  
  126.     dose_left = TheVolume * drug_conc
  127.     call NUM2STR( f , dose_left / 1000. , %ref(s) )
  128.     call SetIText ( %val(dleft_handle) , %ref(s) )
  129.  
  130.     fluid_left = TheVolume
  131.     call NumToString ( %val(int4(TheVolume)) , %ref(s) )
  132.     call SetIText ( %val(vleft_handle) , %ref(s) )
  133.  
  134.     call SelIText ( %val(ptr) , %val(Drug_amount_num) , %val(int2(0)) , %val(int2(32767)) )
  135.     call ShowWindow ( %val(ptr) )
  136.     
  137. c  Wait for user to enter something
  138.  
  139.     DONE = .false.
  140.     do while ( .not. DONE )
  141.         call ModalDialog ( NumValFilter , ItemHit )
  142.         If (ItemHit .eq. new_drug_bag ) then
  143.             DONE = .true.
  144.  
  145.             drug_conc   = temp_conc
  146.             volume_hung = temp_volume
  147.             dose_hung   = temp_dose * 1000.0
  148.             dose_left   = dose_hung
  149.  
  150.             bagnum = bagnum+1
  151.             DRUGHandle.hndl = NewHandle ( %val(JSIZEOF(DRUGResourceType)) )
  152.             call HLock ( %val(DRUGHandle.hndl) )
  153.             DRUGHandle.hndl^.ptr^.bagnum = bagnum
  154.             DRUGHandle.hndl^.ptr^.drug_type = SNPtype
  155.             DRUGHandle.hndl^.ptr^.volume_hung = volume_hung
  156.             DRUGHandle.hndl^.ptr^.dose_hung = temp_dose
  157.             call TheTime ( %val (InDriver) , msgtime )
  158.             DRUGHandle.hndl^.ptr^.bagTime = msgtime
  159.             call NumToString ( %val(int4(bagnum)) , %ref(bagnumString) )
  160.             ResourceNameString = 'New bag #' // bagnumString
  161.             theID = UniqueID ( %val('DRUG') )
  162.             call AddResource ( %val(DRUGHandle.hndl) , %val('DRUG') , %val(theID) ,
  163.     1                                    %ref(ResourceNameString) )
  164.             call UpdateResFile ( %val(curResFile()) )
  165.             call ReleaseResource ( %val(DRUGHandle.hndl) )
  166.                 
  167.             MyCntrlParam = NewPtr ( %val(JSIZEOF(ParamBlockRec)) )
  168.             MyCntrlParam^.ioCompletion.pptr = 0
  169.             MyCntrlParam^.csCode = SetVolume
  170.             MyCntrlParam^.csParam(0) = volume_hung
  171.             MyCntrlParam^.ioCRefNum = OutDriver
  172.             osErr = PBStatus ( %val(MyCntrlParam) , %val(int2(TRUE)) )
  173.            
  174.         ElseIf ( ItemHit .eq. Cancel ) then
  175.             DONE = .true.
  176.  
  177.         ElseIf ( ItemHit .eq. Drug_amount_num ) then
  178.             call GetIText ( %val(dose_handle) , %ref(s) )
  179.             temp_dose = STR2NUM ( %ref(s) )
  180.             temp_conc = temp_dose*1000.0 / temp_volume
  181.             call NUM2STR( f , temp_conc , %ref(s) )
  182.             call SetIText ( %val(conc_handle) , %ref(s) )
  183.         ElseIf ( ItemHit .eq. Diluent_vol_num ) then
  184.             call GetIText ( %val(volume_handle) , %ref(s) )
  185.             call StringToNum ( %ref(s) , temp_volume )
  186.             temp_conc = temp_dose*1000.0 / temp_volume
  187.             call NUM2STR( f , temp_conc , %ref(s) )
  188.             call SetIText ( %val(conc_handle) , %ref(s) )
  189.         Else
  190.             continue
  191.         EndIf
  192.     End Do
  193.  
  194.     call DisposDialog ( %val(ptr) )
  195.     call ReleaseResource ( %val(formatHandle) )
  196.     call SetPort ( %val(prevPort) )
  197.  
  198.     return
  199.     end
  200.